Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve issue #83: generate_steady_states fails when you edit a model's optimal percentage twice #83 #85

Closed
wants to merge 1 commit into from

Conversation

rkstu
Copy link
Contributor

@rkstu rkstu commented Feb 10, 2024

This is related to GeomScale/dingo issue #83 - #83

Reproduced the specified issue (referenced as #83) in my local development environment.

model = dingo.MetabolicNetwork.from_json("ext_data/e_coli_core.json")

model.set_opt_percentage(90)
sampler = dingo.PolytopeSampler(model)
sampler.generate_steady_states()

model.set_opt_percentage(20)
sampler = dingo.PolytopeSampler(model)
sampler.generate_steady_states()
OUTPUT: UnboundLocalError: local variable 'v' referenced before assignment

Error is related to the

v = model.getVars()
and the status == GRB.OPTIMAL that is not the case in the second edit.

Source: - Trying to access a variable which is defined only if status == GRB.OPTIMAL in

                # If optimized
                status = model.status
                if status == GRB.OPTIMAL:
                    optimum_value = -model.getObjective().getValue()
                    v = model.getVars() 

Solution: - Access variable only if it is declared

                # If optimized
                status = model.status
                if status == GRB.OPTIMAL:
                    optimum_value = -model.getObjective().getValue()
                    v = model.getVars()

                    for i in range(n):
                        optimum_sol.append(v[i].x)

OUTPUT after modification :

phase 1: number of correlated samples = 500, effective sample size = 6, ratio of the maximum singilar value over the minimum singular value = 2175.82
phase 2: number of correlated samples = 500, effective sample size = 143, ratio of the maximum singilar value over the minimum singular value = 5.51623
phase 3: number of correlated samples = 500, effective sample size = 158, ratio of the maximum singilar value over the minimum singular value = 2.59844
phase 4: number of correlated samples = 1700, effective sample size = 770
[5]total ess 1077: number of correlated samples = 3200
[5]maximum marginal PSRF: 1.05362


phase 1: number of correlated samples = 600, effective sample size = 4, ratio of the maximum singilar value over the minimum singular value = 2611.83
phase 2: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 2274.04
phase 3: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3640.99
phase 4: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 5323.01
phase 5: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4125.15
phase 6: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3424.12
phase 7: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4738.09
phase 8: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 5004.78
phase 9: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3640.73
phase 10: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3435.86
phase 11: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3554.87
phase 12: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4256.1
phase 13: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4137.46
phase 14: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3557.47
phase 15: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3842.69
phase 16: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3625.27
phase 17: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3911.47
phase 18: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4738.21
phase 19: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4355.26
phase 20: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3726.65
phase 21: number of correlated samples = 2800, effective sample size = 18
phase 22: number of correlated samples = 2800, effective sample size = 18
phase 23: number of correlated samples = 2800, effective sample size = 18
phase 24: number of correlated samples = 2800, effective sample size = 18
phase 25: number of correlated samples = 2800, effective sample size = 18
phase 26: number of correlated samples = 2800, effective sample size = 18
phase 27: number of correlated samples = 2800, effective sample size = 18
phase 28: number of correlated samples = 2800, effective sample size = 17
phase 29: number of correlated samples = 2800, effective sample size = 18
phase 30: number of correlated samples = 2800, effective sample size = 18
phase 31: number of correlated samples = 2800, effective sample size = 18
phase 32: number of correlated samples = 2800, effective sample size = 17
phase 33: number of correlated samples = 2800, effective sample size = 18
phase 34: number of correlated samples = 2800, effective sample size = 18
phase 35: number of correlated samples = 2800, effective sample size = 18
phase 36: number of correlated samples = 2800, effective sample size = 18
phase 37: number of correlated samples = 2800, effective sample size = 17
phase 38: number of correlated samples = 2800, effective sample size = 18
phase 39: number of correlated samples = 2800, effective sample size = 18
phase 40: number of correlated samples = 2800, effective sample size = 18
phase 41: number of correlated samples = 2800, effective sample size = 18
phase 42: number of correlated samples = 2800, effective sample size = 18
phase 43: number of correlated samples = 2800, effective sample size = 18
phase 44: number of correlated samples = 2800, effective sample size = 17
phase 45: number of correlated samples = 2800, effective sample size = 17
phase 46: number of correlated samples = 2800, effective sample size = 17
phase 47: number of correlated samples = 2800, effective sample size = 18
phase 48: number of correlated samples = 2800, effective sample size = 18
phase 49: number of correlated samples = 2800, effective sample size = 18
phase 50: number of correlated samples = 2800, effective sample size = 18
phase 51: number of correlated samples = 2800, effective sample size = 18
phase 52: number of correlated samples = 2800, effective sample size = 18
phase 53: number of correlated samples = 2800, effective sample size = 18
phase 54: number of correlated samples = 2800, effective sample size = 17
phase 55: number of correlated samples = 2800, effective sample size = 19
phase 56: number of correlated samples = 2800, effective sample size = 18
phase 57: number of correlated samples = 2800, effective sample size = 18
phase 58: number of correlated samples = 2800, effective sample size = 17
phase 59: number of correlated samples = 2800, effective sample size = 17
phase 60: number of correlated samples = 2800, effective sample size = 19
phase 61: number of correlated samples = 2800, effective sample size = 18
phase 62: number of correlated samples = 2800, effective sample size = 17
phase 63: number of correlated samples = 2800, effective sample size = 17
phase 64: number of correlated samples = 2800, effective sample size = 18
phase 65: number of correlated samples = 2800, effective sample size = 18
phase 66: number of correlated samples = 2800, effective sample size = 17
phase 67: number of correlated samples = 2800, effective sample size = 17
phase 68: number of correlated samples = 2800, effective sample size = 17
phase 69: number of correlated samples = 2800, effective sample size = 17
phase 70: number of correlated samples = 2800, effective sample size = 18
phase 71: number of correlated samples = 2800, effective sample size = 18
phase 72: number of correlated samples = 2800, effective sample size = 17
phase 73: number of correlated samples = 2800, effective sample size = 18
[5]total ess 1001: number of correlated samples = 160400
[5]maximum marginal PSRF: 1.01239


Segmentation fault (core dumped)

@vfisikop
Copy link
Contributor

Thanks for opening this PR. It seems there is a segfault at the end of your output. Did you debug it? Any ideas for the reason?

@rkstu
Copy link
Contributor Author

rkstu commented Feb 22, 2024

Hi, thanks for your response, and sorry for the late reply. I am currently involved with mid evaluation of my research project. I believe I have a good idea of what's causing it. I will work on it this Saturday and will get back to you with my findings.

@rkstu
Copy link
Contributor Author

rkstu commented Feb 26, 2024

I have been working on this issue for the past few days and tried multiple solutions(not yet resolved) like this https://itslinuxfoss.com/fix-segmentation-fault-core-dumped-linux. According to this the Python segmentation fault is a standard error that arises when a program tries to access a memory that can not be accessed, and this may occur when either the memory location is not accessible or the memory is only available for reading.

Below is one of the implementations: Installed everything from the beginning and ran the below code after the previously suggested modification and suggested according to https://www.pythonclear.com/errors/python-segmentation-fault/

CODE(sample.py):

import os
import numpy as np

# 
import faulthandler

faulthandler.enable()

from dingo import MetabolicNetwork, PolytopeSampler

model = MetabolicNetwork.from_json("ext_data/e_coli_core.json")

model.set_opt_percentage(90)
sampler = PolytopeSampler(model)
result = sampler.generate_steady_states()
print("result = ", result)

print()
model.set_opt_percentage(20)
sampler = PolytopeSampler(model)
result = sampler.generate_steady_states()
print("result = ", result)

OUTPUT:

(dingo-py3.8) (base) @rkstu ➜ /workspaces/dingo (develop) $ python sample.py
phase 1: number of correlated samples = 500, effective sample size = 9, ratio of the maximum singilar value over the minimum singular value = 1527.83
phase 2: number of correlated samples = 500, effective sample size = 178, ratio of the maximum singilar value over the minimum singular value = 3.86279
phase 3: number of correlated samples = 500, effective sample size = 165, ratio of the maximum singilar value over the minimum singular value = 2.58985
phase 4: number of correlated samples = 1600, effective sample size = 668
[5]total ess 1020: number of correlated samples = 3100
[5]maximum marginal PSRF: 1.05368


result =  [[8.50434308e+00 9.66350846e+00 9.39700308e+00 ... 7.51124529e+00
  8.60159689e+00 8.67179327e+00]
 [1.77704917e-01 2.06917943e-04 2.70351996e-01 ... 6.99530546e-01
  1.87361599e-01 5.03524893e-02]
 [4.05018110e+00 8.86140170e+00 8.93308323e+00 ... 2.62244609e+00
  7.34614419e+00 4.45024170e+00]
 ...
 [4.33880811e+00 4.35079329e+00 4.38369869e+00 ... 4.37962864e+00
  4.39131559e+00 4.41066573e+00]
 [2.26832005e+01 2.29626391e+01 2.28987659e+01 ... 2.27908318e+01
  2.39417570e+01 2.28841155e+01]
 [1.21675535e+01 1.18067119e+01 1.06595294e+01 ... 1.13395013e+01
  1.15264293e+01 1.35121617e+01]]

phase 1: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 2247.49
phase 2: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3422.12
phase 3: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3862.91
phase 4: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 6129.42
phase 5: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3140.14
phase 6: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4808.27
phase 7: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3211.05
phase 8: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4277.99
phase 9: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4230.69
phase 10: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3479.24
phase 11: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3711.94
phase 12: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 2915.47
phase 13: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4104.06
phase 14: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4392.43
phase 15: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4137.82
phase 16: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3717.98
phase 17: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 4816.69
phase 18: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 3873.1
phase 19: number of correlated samples = 600, effective sample size = 4, ratio of the maximum singilar value over the minimum singular value = 3637.08
phase 20: number of correlated samples = 600, effective sample size = 3, ratio of the maximum singilar value over the minimum singular value = 5120.2
phase 21: number of correlated samples = 2800, effective sample size = 17
phase 22: number of correlated samples = 2800, effective sample size = 17
phase 23: number of correlated samples = 2800, effective sample size = 18
phase 24: number of correlated samples = 2800, effective sample size = 18
phase 25: number of correlated samples = 2800, effective sample size = 17
phase 26: number of correlated samples = 2800, effective sample size = 19
phase 27: number of correlated samples = 2800, effective sample size = 18
phase 28: number of correlated samples = 2800, effective sample size = 17
phase 29: number of correlated samples = 2800, effective sample size = 18
phase 30: number of correlated samples = 2800, effective sample size = 17
phase 31: number of correlated samples = 2800, effective sample size = 18
phase 32: number of correlated samples = 2800, effective sample size = 18
phase 33: number of correlated samples = 2800, effective sample size = 18
phase 34: number of correlated samples = 2800, effective sample size = 19
phase 35: number of correlated samples = 2800, effective sample size = 18
phase 36: number of correlated samples = 2800, effective sample size = 18
phase 37: number of correlated samples = 2800, effective sample size = 18
phase 38: number of correlated samples = 2800, effective sample size = 17
phase 39: number of correlated samples = 2800, effective sample size = 17
phase 40: number of correlated samples = 2800, effective sample size = 17
phase 41: number of correlated samples = 2800, effective sample size = 17
phase 42: number of correlated samples = 2800, effective sample size = 18
phase 43: number of correlated samples = 2800, effective sample size = 17
phase 44: number of correlated samples = 2800, effective sample size = 18
phase 45: number of correlated samples = 2800, effective sample size = 17
phase 46: number of correlated samples = 2800, effective sample size = 17
phase 47: number of correlated samples = 2800, effective sample size = 17
phase 48: number of correlated samples = 2800, effective sample size = 18
phase 49: number of correlated samples = 2800, effective sample size = 18
phase 50: number of correlated samples = 2800, effective sample size = 18
phase 51: number of correlated samples = 2800, effective sample size = 19
phase 52: number of correlated samples = 2800, effective sample size = 17
phase 53: number of correlated samples = 2800, effective sample size = 18
phase 54: number of correlated samples = 2800, effective sample size = 17
phase 55: number of correlated samples = 2800, effective sample size = 17
phase 56: number of correlated samples = 2800, effective sample size = 17
phase 57: number of correlated samples = 2800, effective sample size = 17
phase 58: number of correlated samples = 2800, effective sample size = 18
phase 59: number of correlated samples = 2800, effective sample size = 18
phase 60: number of correlated samples = 2800, effective sample size = 17
phase 61: number of correlated samples = 2800, effective sample size = 18
phase 62: number of correlated samples = 2800, effective sample size = 18
phase 63: number of correlated samples = 2800, effective sample size = 18
phase 64: number of correlated samples = 2800, effective sample size = 18
phase 65: number of correlated samples = 2800, effective sample size = 18
phase 66: number of correlated samples = 2800, effective sample size = 18
phase 67: number of correlated samples = 2800, effective sample size = 18
phase 68: number of correlated samples = 2800, effective sample size = 18
phase 69: number of correlated samples = 2800, effective sample size = 18
phase 70: number of correlated samples = 2800, effective sample size = 17
phase 71: number of correlated samples = 2800, effective sample size = 18
phase 72: number of correlated samples = 2800, effective sample size = 18
phase 73: number of correlated samples = 2800, effective sample size = 17
phase 74: number of correlated samples = 700, effective sample size = 4
[5]total ess 1001: number of correlated samples = 161100
[5]maximum marginal PSRF: 1.03283


result =  [[ 1.99494778e+05  1.90402552e+05  1.95591544e+05 ...  1.22488764e+66
   1.22469447e+66  1.28782297e+66]
 [ 9.93933482e+04  1.05982044e+05  1.05562962e+05 ...  1.04174710e+65
   1.09310545e+65  1.21504047e+65]
 [-6.39087434e+04 -5.91314238e+04 -6.01278660e+04 ... -1.18676461e+66
  -1.18461540e+66 -1.21453008e+66]
 ...
 [-1.27883839e+06 -1.34145288e+06 -1.31008236e+06 ... -3.16297253e+67
  -3.16333915e+67 -3.27432157e+67]
 [ 5.12334170e+05  5.89589024e+05  5.89608554e+05 ...  9.66932148e+66
   9.67222626e+66  1.00156504e+67]
 [ 2.41106826e+05  2.16087893e+05  2.31796667e+05 ...  2.53361808e+66
   2.52803055e+66  2.68961096e+66]]
Fatal Python error: Segmentation fault

Current thread 0x00007f57c4b0e740 (most recent call first):
<no Python frame>
Segmentation fault (core dumped)

Any suggestions on how to approach this efficiently?

@vfisikop
Copy link
Contributor

You have to debug the code to see exactly where the segfault comes from. It is possible that it comes from the c++ code (roughly speaking it is compiled to python modules via cython). So this is one link that you could start https://cython.readthedocs.io/en/latest/src/userguide/debugging.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants